<?php

namespace App\Http\Controllers\View;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Entity\Product;
use App\Entity\cartitem;
class OrderController extends Controller
{
  public function toOrderCommit(Request $request,$product_ids)
  { 
      $product_ids_arr=($product_ids!=null?explode(',',$product_ids):array());
      $member=$request->session()->get('member','');
      $cart_items=CartItem::where('member_id',$member->id)->whereIn('product_id',$product_ids_arr)->get();
      $cart_item_arr=array();
      $total_price=0;
      foreach($cart_items as $cart_item){
         $cart_item->product=Product::find($cart_item->product_id);
         if($cart_item->product!=null){
             $total_price=$cart_item->product->price*$cart_item->count;
             array_push($cart_item_arr,$cart_item);
         }
      }
      return view('order_commit')->with('cart_items',$cart_item_arr)->with('total_price',$total_price);
  }
  public function toOrderList(){
      return view('orderlist')
  }
}
